<?php
class Shop_Model_Index extends Shop_Model_Base{

    protected function generateSql($params, &$db_params)
    {
		$condKeyword = '';
		
		// ダミー店舗除外
		$condKeyword .= $this->generateNotinDummyShop("M05_TENPO_CD", $db_params);

$sql = <<< DOC_END

SELECT
        M05_KAITENBI
        ,M05_TENPO_TODOUFUKEN_CD
        ,M05_TENPO_TODOUFUKEN
        ,M05_TENPO_CD
        ,M05_TENPO_NAME
        ,M93_CONNECTION_NO6
    FROM
        M05TENPO_INFO
        ,M93CALLNOTE
        ,(
            SELECT
                    MIN(M05_KAITENBI) AS MIN_M05_KAITENBI
                FROM
                    (
                        SELECT
                                M05_KAITENBI
                                ,M05_TENPO_TODOUFUKEN_CD
                                ,M05_TENPO_TODOUFUKEN
                                ,M05_TENPO_CD
                                ,M05_TENPO_NAME
                                ,M93_CONNECTION_NO6
                            FROM
                                M05TENPO_INFO
						        ,M93CALLNOTE
                                WHERE
                                M05_KAITENBI >= TO_CHAR(ADD_MONTHS(SYSDATE, -6), 'yyyy-mm-dd')
                                AND M05_KOUKAI_FLAG = 1
                                AND M05_TENPO_CD > '01000000'
                                AND M05_TENPO_CD < '48000000'
								{$condKeyword}
                                AND M05_TENPO_CD = M93_TENPO_CD
                            ORDER BY
                                M05_KAITENBI DESC
                                ,M05_TENPO_TODOUFUKEN_CD ASC
                                ,M05_TENPO_SHIKUCHOUSON_CD ASC
                                ,M05_TENPO_CHOUMEI_CD ASC
                                ,M05_TENPO_CHOUMOKU_CD ASC
                    )
                WHERE
                    ROWNUM <= 10
        )
    WHERE
        MIN_M05_KAITENBI IS NOT NULL
        AND M05_KAITENBI >= MIN_M05_KAITENBI
        AND M05_KOUKAI_FLAG = 1
        AND M05_TENPO_CD > '01000000'
        AND M05_TENPO_CD < '48000000'
		{$condKeyword}
        AND M05_TENPO_CD = M93_TENPO_CD
    ORDER BY
        M05_KAITENBI DESC
        ,M05_TENPO_TODOUFUKEN_CD ASC
        ,M05_TENPO_SHIKUCHOUSON_CD ASC
        ,M05_TENPO_CHOUMEI_CD ASC
        ,M05_TENPO_CHOUMOKU_CD ASC

DOC_END;
        return $sql;
    }
	
}
?>
